package com.basker.pisces.core.query.factory;

import java.util.ArrayList;
import java.util.List;

import org.springframework.util.Assert;

import com.basker.pisces.core.query.IQuery.PagingInfo;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
public class SimpleQueryInfo extends AbstractQueryInfo {

    /**
     * 分页号，从1开始,null表示不分页
     */
    private Integer pageIndex;

    /**
     * 每页大小，必须>0,null表示不分页
     */
    private Integer pageSize;

    /**
     * 需要查询的字段，为空默认查询所有主实体的属性
     */
    private List<String> selectFields = new ArrayList<>();

    public void addSelectFields(String... selectFields) {
        for (String selectField : selectFields) {
            Assert.hasLength(selectField, "parameter 'selectField' is required");

            this.selectFields.add(selectField);
        }
    }

    /**
     * 构建一个分页查询对象
     *
     * @return
     */
    public PagingInfo buildPagingInfo() {
        return new PagingInfo(pageIndex, pageSize);
    }

}
